package com.napier.unit3;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class P3_Vibrate extends Activity 
{
	
	private Vibrator vibrator;
	private Button start_button, stop_button;

    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Vibrator creation
        vibrator = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
        
        // Button creation
        start_button = (Button)findViewById(R.id.start_button_id);
        stop_button = (Button)findViewById(R.id.stop_button_id);

        start_button.setOnClickListener(new OnClickListener() 
        {
        	public void onClick(View v) 
        	{
        		long[] pattern = {0,200,200,200,200,200, // start, dot, gap, dot, gap, dot ==> S
    					500,				 // gap
    					500,200,500,200,500, // dash, gap, dash, gap, dash 	               ==> O 
    				  	500,				 // gap
    				  	200,200,200,200,200, // dot, gap, dot, gap, dot                    ==> S
    				  	1000};               // long gap == finish
        		vibrator.vibrate(pattern, -1);
        	}    			
        });
        
        stop_button.setOnClickListener(new OnClickListener() 
        {
			public void onClick(View arg0) 
			{
				vibrator.cancel();
			}
        });
    }
}